package com.bwie.service.impl;

import com.bwie.exception.BusinessException;
import com.bwie.mapper.ChargingMapper;
import com.bwie.pojo.dto.ChargingDto;
import com.bwie.pojo.excel.ChargingExcel;
import com.bwie.pojo.po.Charging;
import com.bwie.service.ChargingService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ChargingServiceImpl implements ChargingService {
    @Autowired
    private ChargingMapper chargingMapper;

    //价格规则列表
    @Override
    public PageInfo<Charging> getCharging(ChargingDto chargingDto) {
        PageHelper.startPage(chargingDto.getPageNum(),chargingDto.getPageSize());
        List<Charging> list = chargingMapper.getChahrging(chargingDto);
        PageInfo<Charging> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void addChargingList(Charging charging) {


        /**
         * 非空校验
         */
        Integer chargingType = charging.getChargingType();
        Integer parkId = charging.getParkId();
        String chargingName = charging.getChargingName();
        BigDecimal chargingPrice = charging.getChargingPrice();

        if (chargingType==null||parkId==null|| StringUtils.isEmpty(chargingName)||chargingPrice==null){
            throw new BusinessException("必要字段不能为空");
        }

        int i = chargingPrice.compareTo(new BigDecimal(0));
        if (i<=0){
            throw new BusinessException("金额不能小于登录0");
        }



        chargingMapper.addCharging(charging);


    }

    @Override
    public List<ChargingExcel> selectListByIds(List<Integer> ids2) {

        return chargingMapper.selectListByIds(ids2);
    }

    @Override
    public List<ChargingExcel> selectListAll() {
        return chargingMapper.selectListAll();
    }

    @Override
    public void batchAdd(List<Charging> list) {
        chargingMapper.batchAdd(list);
    }

    @Override
    public List<Charging> getChargingList() {
        ChargingDto chargingDto = new ChargingDto();
        List<Charging> list = chargingMapper.getChahrging(chargingDto);
        return list;
    }
}
